from urllib import request
from urllib import parse
from fake_useragent import UserAgent
#实例化一个对象
ua=UserAgent()

# url = "https://www.baidu.com/s?ie=UTF-8&wd={}"
url = "http://www.hao123.com/"


# word = input('请输入搜索信息')

# params = parse.quote(word)
#
# # print(params)
#
# url = url.format(params)

headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
}

req = request.Request(url=url,headers=headers)

response = request.urlopen(req)

html = response.read().decode('utf-8')

print(html)
with open('hao123.html', 'w', encoding='utf-8') as f:
    f.write(html)
